package com.example.administrator.hqq.adapter.dating;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.ScreenUtils;
import com.bumptech.glide.Glide;
import com.example.administrator.hqq.R;
import com.example.administrator.hqq.bean.dating.DatingListBean;

import org.w3c.dom.Text;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import me.nereo.multi_image_selector.bean.Image;

/**
 * @name: HQQ
 * @describe:
 * @author: 康海涛 QQ2541849981
 * @time: 2019/1/6 16:36
 * @remark:
 */
public class DatingListAdapter extends RecyclerView.Adapter<DatingListAdapter.ViewHolder> {
    private Context context;
    private List<DatingListBean.DataBean> data;
    private DatingListClick datingListClick;
    public DatingListAdapter(Context context, List<DatingListBean.DataBean> data) {
        this.context = context;
        this.data = data;
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.image)
        ImageView imageView;
        @BindView(R.id.introduce)
        TextView introduce;
        View view;
        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            view=itemView;
        }
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.dating_list_item, parent,false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        ViewGroup.LayoutParams layoutParams = holder.imageView.getLayoutParams();
        Glide.with(context).load(data.get(position).getPicture_url())
                .override(521,data.get(position).getImage_height())
                .fitCenter().into(holder.imageView);
        holder.introduce.setText(data.get(position).getText());
        holder.view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (datingListClick!=null){
                    datingListClick.click(position,holder.imageView);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public void setDatingListClick(DatingListClick datingListClick) {
        this.datingListClick = datingListClick;
    }

   public interface DatingListClick{
        void click(int position,ImageView imageView);
    }
}
